import React, { Component, lazy, Suspense } from 'react'
import { Routes, Route, NavLink } from 'react-router-dom'
// import Home from './Home';
// import About from './About';

// 路由懒加载
const Home = lazy (() => import ('./Home'))
const About = lazy (() => import ('./About'))


export default class RouterLazyLoad extends Component {

  render() {
    return (
      <div>
        <div className="row">
          <div className="col-xs-offset-2 col-xs-8">
            <h2>router lazyLoad</h2>
          </div>
        </div>

        <div className="row">
          <div className="col-xs-2 col-xs-offset-2">
            <div className="list-group">

              <NavLink to='/home' className="list-group-item">Home</NavLink> 
              <NavLink to='/about' className="list-group-item">About</NavLink>

            </div>
          </div>

          <div className="col-xs-6">
            <div className="panel">
              <div className="panel-body">
                {/* 注册路由 */}
                <Suspense fallback={<h1>Loading.....</h1>}>
                  <Routes>
                    <Route  path='/about' element={<About />} />
                    <Route path='/home' element={<Home />} />
                  </Routes>
                </Suspense>
                
              </div>
            </div>
          </div>
        </div>
      </div>
    );
  }
}


